/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cedict.domain;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 *
 * @author andrew
 */
@Entity
@Table(name="cedict_definition")
public class CedictRowDefinition implements Serializable {

    @Id
    @GeneratedValue
    private Long id;
    @ManyToOne(optional=false)
    @JoinColumn(nullable=false)
    private UTF8CedictRow cedictRow;
    @Column(name="definition_order")
    private Integer order;
    @Column(nullable=false, length=1024)
    private String definition;

    public CedictRowDefinition() {
    }

    public CedictRowDefinition(UTF8CedictRow cedictRow, Integer order,
            String definition)
    {
        this.cedictRow = cedictRow;
        this.order = order;
        this.definition = definition;
    }
    
    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the cedictRow
     */
    public UTF8CedictRow getCedictRow() {
        return cedictRow;
    }

    /**
     * @param cedictRow the cedictRow to set
     */
    public void setCedictRow(UTF8CedictRow cedictRow) {
        this.cedictRow = cedictRow;
    }

    /**
     * @return the order
     */
    public Integer getOrder() {
        return order;
    }

    /**
     * @param order the order to set
     */
    public void setOrder(Integer order) {
        this.order = order;
    }

    /**
     * @return the definition
     */
    public String getDefinition() {
        return definition;
    }

    /**
     * @param definition the definition to set
     */
    public void setDefinition(String definition) {
        this.definition = definition;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) { return false; }
        if (obj == this) { return true; }
        if (!(obj instanceof CedictRowDefinition)) { return false; }
        CedictRowDefinition def = (CedictRowDefinition) obj;
        return new EqualsBuilder().
                append(def.order, order).
                append(def.definition, definition).
                isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().
                append(order).
                append(definition).
                hashCode();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).
                append(order).
                append(definition).
                toString();
    }

}
